﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MentalAlchemy.Molecules.Image;

namespace MentalAlchemy.Compounds.Image
{
	public partial class ImageDescriptionLoaderControl : UserControl
	{
		#region - Properties. -
		/// <summary>
		/// List of loaded image descriptions.
		/// </summary>
		public List<SparseImageDescription> Descriptions { get; set; }

		/// <summary>
		/// Name of the file containing image descriptions.
		/// </summary>
		public string Filename
		{
			get
			{
				return DescriptionFilenameBox.Text;
			}
		}

		/// <summary>
		/// Control's title shown to the user.
		/// </summary>
		public string Caption
		{
			get
			{
				return groupBox1.Text;
			}
			set
			{
				groupBox1.Text = value;
			}
		}
		#endregion

		#region - Initialization. -
		public ImageDescriptionLoaderControl()
		{
			InitializeComponent();
		} 
		#endregion

		#region - Event handlers. -
		private void LoadDescriptionBtn_Click(object sender, EventArgs e)
		{
			var res = openFileDialog1.ShowDialog();

			if (res == DialogResult.OK)
			{
				try
				{
					Descriptions = ImageDescriptionElements.Deserialize(openFileDialog1.FileName);
				}
				catch (Exception ex)
				{
					throw new Exception("[LoadDescriptionBtn_Click]: Error during deserialization of the sparse image descriptions. (" + ex + ")");
				}

				DescriptionFilenameBox.Text = openFileDialog1.FileName;
			}
		} 
		#endregion
	}
}
